<?php

/**
 * XHTML Document, Head > Script
 * 
 * @package Core
 * @subpackage Document
 *
 */
class Lead_Controller_Response_Document_Head_Script extends Lead_Controller_Response_Document_Head_Part 
{
	
	
	/**
	 * Script data
	 *
	 * @var array
	 */
	private $_scripts = array();
	
	private $_scriptBlocks = array();
	
	
				
	/**
	 * Adds a script
	 *
	 * @param string $value Script URI
	 */
	function add($value, $location = 1)
	{
		$addArr = array('type' => "text/javascript", 'src' => $value);
	    
	    if($location == 0)
		      array_unshift($this->_scripts, $addArr);
		
	    $this->_scripts[] = $addArr;
	}
	
	
	function addBlock($block)
	{
	    $this->_scriptBlocks[] = $block;
	}
	
	
	
	
	/**
	 * Renders scripts.
	 *
	 * @return string
	 */
	function render()
	{
		$output = array();
		foreach($this->_scripts as $stylekey => &$stylevalue)
		{
			$output[] = "<script type=\"{$stylevalue['type']}\" src=\"{$stylevalue['src']}\"></script>";
		}
		
		if($this->_scriptBlocks) {
		    $output[] = implode('\n\n', $this->_scriptBlocks);
		}
		
		
		return implode("\n", $output);
	}
	
	
	
	
}
?>